<template>
  <!-- 处理提现的弹窗 -->
  <el-dialog
    class="pick-dialog"
    :title="title"
    :visible.sync="dialogVisible"
    :close-on-click-modal="false"
    width="1100px"
  >
    <div class="form-box" v-loading="loading"> 
      <div class="orderTable" >
        <el-table :data="orderList" border style="width: 100%">
          <el-table-column prop="applicantName" label="申请人昵称"></el-table-column>
          <el-table-column prop="applicantRealName" label="真实姓名"></el-table-column>
          <el-table-column prop="createTime" label="申请时间"></el-table-column>
          <el-table-column
            prop="amount"
            label="提现金额"
            min-width="150"
          ></el-table-column>
          <el-table-column prop="" label="账号类型">
            <template slot-scope="scope">
              <span>{{commonMaps.accountType[scope.row.accountType]}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="account" label="收款账号"> </el-table-column>

        </el-table>
        <div class="total-amount flex">
          <h3>提现金额：</h3>
          <div class="price">
            {{ info.amount }}元
          </div>
        </div>
      </div>
      <el-form
        :model="ruleForm"
        ref="ruleForm"
        label-width="auto"
        :rules="rules"
        class="demo-ruleForm"
      >
      <el-form-item label="打款时间:" prop="sucessTime">
        <el-date-picker
      v-model="ruleForm.sucessTime"
      type="datetime"
      format="yyyy-MM-dd HH:mm:ss"
      value-format="yyyy-MM-dd HH:mm:ss"
      placeholder="选择打款时间"
      >
    </el-date-picker>
        </el-form-item>
        <el-form-item
          label="上传图片:"
          prop="afterImg"
        >
          <el-upload
            :action="uploadImgUrl"
            list-type="picture-card"
            :file-list="imgShowList0"
            :multiple="true"
            :on-preview="handlePictureCardPreview"
            :on-success="handleUploadSuccess0"
            :on-remove="handleRemove0"
            :limit="9"
          >
            <i class="el-icon-plus"></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="补充描述:" prop="remark">
          <el-input
            style="width: 600px"
            v-model="ruleForm.remark"
            type="textarea"
            rows="5"
            placeholder="请输入结算补充描述..."
          ></el-input>
        </el-form-item>
      </el-form>
      <div class="center">
        <el-button @click="close('ruleForm')">关闭</el-button>
        <el-button
          type="primary"
          @click="submitForm('ruleForm',1)"
          :loading="loading"
          >确认已打款</el-button
        >
      </div>
    </div>
  </el-dialog>
</template>

<script>
import orderAfterApi from "@/api/pickUp/afterSale.js";
import billListApi from "@/api/financeCenter/billList.js";
import { formatDate } from "@/utils/index";
export default {
  name: "",
  data() {
    return {
      title: "提现结算",
      dialogVisible: false,
      loading: false,
      // 上传相关
      uploadImgUrl: "",
      imgShowList0: [],
      newImages0: [],
      imgFileList0: [],
      // end
      ruleForm: {
        sucessTime:'', 
        orderIds: [],
        userId: "",
        userName: "",
        img: "",
        remark: "",
        auditState:''
      },
      rules: {},
      from: "", //来源
      buyerOrSeller: "",
      buyers: [],
      sellers: [],
      orderList: [],
      selectOrders: [],
      totalAmount: 0, //选中项的合计总额

      info: {},
    };
  },
  created() {
    this.uploadImgUrl = process.env.VUE_APP_BASE_API + "/upload/image";
  },
  methods: {
    open(data) {
      this.loading = false;
      this.imgShowList0 = [];
      this.newImages0 = [];
      this.imgFileList0 = [];
      this.orderList = [data]
      this.info = data
      this.ruleForm = {
        sucessTime: formatDate(new Date()), 
        orderIds: [],
        userId: "",
        userName: "",
        img: "",
        remark: "",
        auditState:''
      };
      this.ruleForm.orderIds = [data.id];
      this.ruleForm.userId = data.applicantId;
      this.ruleForm.userName = data.applicantName;
      this.dialogVisible = true;
    },
    submitForm(formName,auditState) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // financialStatementSaleOrder
          // 组装图片附件
          // 拼接新上传的图片
          let ziliao = [];
          if (this["newImages0"] && this["newImages0"].length) {
            let newArr = [];
            this["newImages0"].forEach((img) => {
              newArr.push({
                name: img.name,
                url: img.response.data.filePath,
              });
            });
            ziliao = this["imgFileList0"].concat(newArr);
          } else {
            ziliao = this["imgFileList0"];
          }
          this.ruleForm.img = JSON.stringify(ziliao);
          this.ruleForm.auditState = auditState
          this.loading = true;
          billListApi.tixianSettlementApi(this.ruleForm).then((res) => {
            this.dialogVisible = false;
            this.loading = false;
            if (res.code == 200) {
              this.$message.success(res.msg);
              this.$parent.getList();
            }
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },

    // 上传图片相关
    // 图片预览
    handlePictureCardPreview(file) {
      this.$viewerApi({
        images: [file.url],
      });
    },
    uploadNumber(file, fileList) {
      //限制图片数量
      this.$modal.msgError("最多只能上传9张图片");
    },
    // 图片上传成功
    handleUploadSuccess0(res, file, fileList) {
      if (res.code == 200) {
        // 取得新上传的文件
        this.newImages0 = fileList.filter((t) => {
          return t.url.indexOf("blob:") > -1;
        });
      }
    },
    // 图片删除
    handleRemove0(response) {
      const that = this;
      // 1.获取将要删除图片的临时路径
      const filePath = response.url;
      // 2.找到图片对应的索引值
      this.imgFileList0.forEach(function (element, key) {
        if (element.url === filePath) {
          that.imgFileList0.splice(key, 1); //回显的图片
        }
      });
      this.newImages0.forEach(function (element, key) {
        if (element.url === filePath) {
          that.newImages0.splice(key, 1); //新上传的图片
        }
      });
    },
    close(formName) {
      this.dialogVisible = false;
    },
  },
};
</script>
<style scoped lang="scss">

.topBtn {
  margin-bottom: 20px;
}
.orderTable {
  margin-top: 20px;
}
.total-amount {
  line-height: 50px;
}
.price {
  font-size: 24px;
  color: crimson;
}
// .names {
//   margin: 20px 0;
// }
.demo-ruleForm {
  margin-top: 20px;
  padding-right: 20px;
}

.center {
  text-align: center;
}



.pick-dialog >>> .el-input--medium input {
  text-align: left;
}
</style>
